﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;

using BlueCMS.Core.Data.Query.Clauses;

namespace BlueCMS.Core.Data.Query
{
    public class UpdateQuery 
    {
        UpdateClause UpdateClause { get; set; }
        SetClause SetClause { get; set; }
        FromClause FromClause { get; set; }
        WhereClause WhereClause { get; set; }

        public Dictionary<string, DbParameter> Parameters { get; private set; }

        public UpdateQuery()
        {
            UpdateClause = new UpdateClause();
            SetClause = new SetClause();
            FromClause = new FromClause();
            WhereClause = new WhereClause();
            Parameters = new Dictionary<string, DbParameter>();
        }

        public UpdateClause Update
        {
            get { return UpdateClause; }
        }

        public ISetClause Set
        {
            get { return SetClause; }
        }

        public IFromClause From
        {
            get { return FromClause; }
        }

        public IWhereClause Where
        {
            get { return WhereClause; }
        }

        public string Sql
        {
            get
            {
                return DataAccess.Instance.GetQueryGenerator().ProcessUpdateQuery(UpdateClause, SetClause, FromClause, WhereClause, Parameters);
            }
        }

        public override string ToString()
        {
            return Sql;
        }
    }
}
